package com.oceansoft.mobile.econsole.modules.weixin.controller;

import com.oceansoft.mobile.econsole.modules.api.v2.service.ICaseService;
import com.oceansoft.mobile.econsole.modules.api.v2.service.IProjectYyService;
import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.matters.entity.CaseInfo;
import com.oceansoft.mobile.econsole.modules.member.entity.WtMember;
import com.oceansoft.mobile.econsole.modules.member.service.IMemberService;
import com.oceansoft.mobile.econsole.modules.member.service.IWtMemberService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * com.oceansoft.mobile.econsole.modules.weixin.controller
 * Created by smc
 * date on 2016/2/29.
 * Email:sunmch@163.com
 */
@Controller
@RequestMapping("api/jgyy")
public class JgYyController extends BaseController {

    @Resource
    private IMemberService memberService;
    @Resource
    private IWtMemberService wtMemberService;
    @Resource
    private ICaseService caseService;
    @Resource
    IProjectYyService projectYyService;

    /**
     * 公安机关提讯、提解犯罪嫌疑人预约
     * @return
     */
    @RequestMapping("gatx")
    public String  gaTx(HttpServletRequest request,Model model){
        WtMember member = null;
        String pt = request.getParameter("pt");
        if("A".equals(pt) || "I".equals(pt)){
            String userGuid = request.getParameter("userGuid");
            member = wtMemberService.getWtMemberByUserGuid(userGuid);
        }else{
            member = super.getWxMemberSession();
        }

        String orgId = request.getParameter("orgId");
        String caseNo = request.getParameter("caseNo");
        CaseInfo caseInfo = caseService.getCaseInfo(caseNo, orgId);

        model.addAttribute("member" , member);
        model.addAttribute("orgId",request.getParameter("orgId"));
        model.addAttribute("orgName",caseInfo.getOrgName());
        model.addAttribute("pt",request.getParameter("pt"));
        model.addAttribute("caseNo",caseNo);
        // 预约日期,监管3天
        List<String> yyrq = projectYyService.getYyDataArrange("3");
        model.addAttribute("yyrq",yyrq);
        return "weixin/jgyy/gatx";
    }

    /**
     * 留所服刑罪犯家属视频会见预约
     * @return
     */
    @RequestMapping("jssp")
    public String  jsSp(HttpServletRequest request,Model model){
        WtMember member = null;
        String pt = request.getParameter("pt");
        if("A".equals(pt) || "I".equals(pt)){
            String userGuid = request.getParameter("userGuid");
            member = wtMemberService.getWtMemberByUserGuid(userGuid);;
        }else{
            member = super.getWxMemberSession();
        }

        String orgId = request.getParameter("orgId");
        String caseNo = request.getParameter("caseNo");
        CaseInfo caseInfo = caseService.getCaseInfo(caseNo, orgId);

        model.addAttribute("member" , member);
        model.addAttribute("orgId",request.getParameter("orgId"));
        model.addAttribute("orgName",caseInfo.getOrgName());
        model.addAttribute("pt",request.getParameter("pt"));
        model.addAttribute("caseNo",caseNo);
        // 预约日期,监管3天
        List<String> yyrq = projectYyService.getYyDataArrange("3");
        model.addAttribute("yyrq",yyrq);
        return "weixin/jgyy/jssp";
    }

    /**
     * 法院提讯、提解被告人预约
     * @return
     */
    @RequestMapping("fytx")
    public String fyTx(HttpServletRequest request,Model model){
        WtMember member = null;
        String pt = request.getParameter("pt");
        if("A".equals(pt) || "I".equals(pt)){
            String userGuid = request.getParameter("userGuid");
            member = wtMemberService.getWtMemberByUserGuid(userGuid);
        }else{
            member = super.getWxMemberSession();
        }

        String orgId = request.getParameter("orgId");
        String caseNo = request.getParameter("caseNo");
        CaseInfo caseInfo = caseService.getCaseInfo(caseNo, orgId);

        model.addAttribute("member" , member);
        model.addAttribute("orgId",request.getParameter("orgId"));
        model.addAttribute("orgName",caseInfo.getOrgName());
        model.addAttribute("pt",request.getParameter("pt"));
        model.addAttribute("caseNo",caseNo);
        // 预约日期,监管3天
        List<String> yyrq = projectYyService.getYyDataArrange("3");
        model.addAttribute("yyrq",yyrq);
        return "weixin/jgyy/fytx";
    }

    /**
     * 检察院提讯、提解犯罪嫌疑人预约
     * @return
     */
    @RequestMapping("jcytx")
    public String jcyTx(HttpServletRequest request,Model model){
        WtMember member = null;
        String pt = request.getParameter("pt");
        if("A".equals(pt) || "I".equals(pt)){
            String userGuid = request.getParameter("userGuid");
            member = wtMemberService.getWtMemberByUserGuid(userGuid);
        }else{
            member = super.getWxMemberSession();
        }

        String orgId = request.getParameter("orgId");
        String caseNo = request.getParameter("caseNo");
        CaseInfo caseInfo = caseService.getCaseInfo(caseNo, orgId);

        model.addAttribute("member" , member);
        model.addAttribute("orgId",request.getParameter("orgId"));
        model.addAttribute("orgName",caseInfo.getOrgName());
        model.addAttribute("pt",request.getParameter("pt"));
        model.addAttribute("caseNo",caseNo);
        // 预约日期,监管3天
        List<String> yyrq = projectYyService.getYyDataArrange("3");
        model.addAttribute("yyrq",yyrq);
        return "weixin/jgyy/jcytx";
    }

    /**
     * 律师会见犯罪嫌疑人(被告人)预约
     * @return
     */
    @RequestMapping("lshj")
    public  String lsHj(HttpServletRequest request,Model model){
        WtMember member = null;
        String pt = request.getParameter("pt");
        if("A".equals(pt) || "I".equals(pt)){
            String userGuid = request.getParameter("userGuid");
            member = wtMemberService.getWtMemberByUserGuid(userGuid);
        }else{
            member = super.getWxMemberSession();
        }

        String orgId = request.getParameter("orgId");
        String caseNo = request.getParameter("caseNo");
        CaseInfo caseInfo = caseService.getCaseInfo(caseNo, orgId);

        model.addAttribute("member" , member);
        model.addAttribute("orgId",request.getParameter("orgId"));
        model.addAttribute("orgName",caseInfo.getOrgName());
        model.addAttribute("pt",request.getParameter("pt"));
        model.addAttribute("caseNo",caseNo);
        // 预约日期,监管3天
        List<String> yyrq = projectYyService.getYyDataArrange("3");
        model.addAttribute("yyrq",yyrq);
        return "weixin/jgyy/lshj";
    }
}
